home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: help about structure
- Date: 3 Jan 1996 10:22:15 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4ce6v7$j6p@umbc9.umbc.edu>
- References: <4c3t9q$aob@chleuasme.francenet.fr>
- NNTP-Posting-Host: f-umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- jo <jobloch@micronet.fr> wrote:
- |> How can I translate from Pascal to C such a structure:
- |> token=record;
- |> begin
- |> nature:tokennature;
- |> case nature : tokennature of
- |> tkinteger: (i:integer);
- |> tkreal: (r:double);
- |> ...
- |> end;
- |>
- |> Can i use "switch" in a structure implementation ?
-
- This is sorta like the FAQ question 20.26:
-
- "Are there programs for converting Pascal or FORTRAN to C?"
-
- Since the answer is obviously yes then any portable Pascal program
- can be written in portable C. I've had great success using a program
- called p2c under UNIX, but there's probably implementations or
- similar programs for MS-DOS. The way p2c does a conversion like this
- is to have a union inside the structure. Here's an example:
-
- typedef enum {tkinteger, tkreal} tokennature;
-
- typedef struct
- {
- tokennature nature;
- union { int i; double r; } U;
- } token;
-
- So you can't have a switch in the structure itself, but will undoubtedly
- be using a switch when accessing the members of the union inside of
- the structure.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-